<?php

/**
 * Customers form.
 *
 * @package    form
 * @subpackage customers
 * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class CustomersForm extends BaseCustomersForm
{
  protected static $subjects = array("M" => "M","F" => "F");
  protected static $newsletter = array("y" => "Yes","n" => "No");
  public function configure()
  {
    unset($this['customers_default_address_id']);
    $this->widgetSchema['customers_gender'] = new sfWidgetFormSelectRadio(array("choices" => self::$subjects),array());
    $this->validatorSchema['customers_gender'] = new sfValidatorChoice(array( "choices" => array_keys(self::$subjects)));
    $this->widgetSchema['customers_newsletter'] = new sfWidgetFormSelectRadio(array("choices" => self::$newsletter),array());
    $this->validatorSchema['customers_newsletter'] = new sfValidatorChoice(array( "choices" => array_keys(self::$newsletter)));
    $address = new AddressBookForm();
    $this->embedForm('AddressBook', $address);
  }

  public function doSave( $con = null )
  {
    parent::doSave($con);
    $addressbook = new AddressBook();
    $addressbook->setCustomers($this->getObject());
    $addarray = $this->getValue('AddressBook');
    $addressbook->setEntryGender($addarray['entry_gender']);
    $addressbook->setEntryCompany($addarray['entry_company']);
    $addressbook->setEntryFirstname($addarray['entry_firstname']);
    $addressbook->setEntryLastname($addarray['entry_lastname']);
    $addressbook->setEntryStreetAddress($addarray['entry_street_address']);
    $addressbook->setEntrySuburb($addarray['entry_suburbr']);
    $addressbook->setEntryPostcode($addarray['entry_postcode']);
    $addressbook->setEntryCity($addarray['entry_city']);
    $addressbook->setEntryState($addarray['entry_state']);
    $addressbook->setEntryCountryId($addarray['entry_country_id']);
    $addressbook->setEntryZoneId($addarray['entry_zone_id']);
    $addressbook->save();
  }
}
